import wx
import tkinter
import requests  
import io  
import sys
from tkinter import StringVar
from tkinter import scrolledtext
from tkinter import messagebox
from bs4 import BeautifulSoup
from bs4 import BeautifulSoup, Comment
from sklearn.feature_extraction.text import TfidfVectorizer
from tf_two_article.tf_two_article.HTML.GET_ART import GET_ART
from tf_two_article.tf_two_article.Samilar.Smi_com import Smi_com
from tf_two_article.tf_two_article.Windows.JUGE import JUGE
import urllib



root= tkinter.Tk()
root.title("刘亚圣")
root.geometry("700x600")
label=tkinter.Label(root,text="请输入网址1:",fg="black",font=("宋体", 10),)
label.grid(column=0,row=0)
##
##photo = tkinter.PhotoImage(file=r"C:\Users\10840\Desktop\背景.png")
##theLabel = tkinter.Label(root,image=photo)#前景色
##theLabel.pack()


e=StringVar()
entry1=tkinter.Entry(root,textvariable=e)
entry1.grid(column=1,row=0)

label2=tkinter.Label(root,text="请输入网址2:",fg="black",font=("宋体", 10),)
label2.grid(column=0,row=1)


b=StringVar()
entry2=tkinter.Entry(root,textvariable=b)
entry2.grid(column=1,row=1)

#网页源码框1
label=tkinter.Label(root,text="文章1:",fg="black",font=("宋体", 10),)
label.grid(column=0,row=2)



texta=scrolledtext.ScrolledText(root,width=35,height=15)
texta.place(x=30,y=90)



#文本提取框1

label=tkinter.Label(root,text="文章1TF:",fg="black",font=("宋体", 10),)
label.place(x=10,y=300)

texta1=scrolledtext.ScrolledText(root,width=35,height=15)
texta1.place(x=30,y=330)


#网页2
label=tkinter.Label(root,text="文章2:",fg="black",font=("宋体", 10),)
label.place(x=330,y=55)

textb=scrolledtext.ScrolledText(root,width=35,height=15)
textb.place(x=350,y=90)

#文本提取框1

label=tkinter.Label(root,text="文章2TF:",fg="black",font=("宋体", 10),)
label.place(x=330,y=300)

textb1=scrolledtext.ScrolledText(root,width=35,height=15)
textb1.place(x=350,y=330)


label2=tkinter.Label(root,text="余弦相似度:",fg="black",font=("宋体", 10),)
label2.place(x=330,y=25)

z=StringVar()
entry3=tkinter.Entry(root,textvariable=z)
entry3.place(x=410,y=25)


def jiexia():
    
    url1 = str(e.get())
    url2 = str(b.get())

    if len(url1)>0 and len(url2)>0:
        ta = JUGE()
        ta1 = ta.juge_url(url1)
        ta2 = ta.juge_url(url2)
        if ta1 == ta2 and ta1 == 1:
            s_art1 = GET_ART(url1)
            s_art2 = GET_ART(url2)
            art11 = s_art1.re_article()
            art22 = s_art2.re_article()
            texta.delete(1.0,'end')
            texta.insert(1.0,art11)
            textb.delete(1.0,'end')
            textb.insert(1.0,art22)
            simi = Smi_com(art11,art22)
            Simi,tfart1,tfart2 = simi.compute()
            simil = str(Simi)+'%'
            texta1.delete(1.0,'end')
            texta1.insert(1.0,tfart1)
            textb1.delete(1.0,'end')
            textb1.insert(1.0,tfart2)
            entry3.insert(0,simil)
        else:
            tkinter.messagebox.showinfo(title='非法输入', message='请输入新浪博客文章链接')  # 通知型弹窗
    else:
        tkinter.messagebox.showinfo(title='非法输入', message='请输入新浪博客文章链接')  # 通知型弹窗
'''    
def jiexib():
    
    
    urll = b.get()
    newsa = Article(urll, language='zh')
    newsa.download()  #先下载
    newsa.parse()    #再解析
    
    textb.delete(1.0,'end')#网页源码
    textb.insert(1.0,newsa.html)

    textb1.delete(1.0,'end')#正文
    textb1.insert(1.0,newsa.title)
    textb1.insert(2.0,newsa.text)
'''




q=tkinter.Button(text="计算",command= jiexia)
q.grid(column=2,row=1)
